/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.loli.hernandez.modelo;


import com.loli.hernandez.modelo.beans.DatabaseTable;
import com.loli.hernandez.modelo.beans.TableColumn;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

/**
 * @author nestor
 */
public class TableColumnPeer {

    public static ArrayList<TableColumn> getColumnsFromTable(DataManager dataManager, 
            DatabaseTable table) throws SQLException{
        String sql = "";
        ArrayList<TableColumn> columnsList = new ArrayList<TableColumn>();
        //show columns from customers ;
        sql = "show columns from `" + table.getTableName() + "`";
        ResultSet rs = dataManager.getResultSetFromQuery(sql);
        
        while (rs.next()) {
            TableColumn column = new TableColumn();
            //Field, Type, Null, Key, Default, Extra
            column.setDefaultValue(rs.getString("default"));
            column.setField(rs.getString("field"));
            column.setType(rs.getString("type"));
            column.setNullAllowed(rs.getString("null"));
            column.setPrimaryKey(rs.getString("key"));
            column.setExtra(rs.getString("extra"));
            columnsList.add(column);
        }
        dataManager.fullDisposeResultSet(rs);
        
        return columnsList;
    }
}
